
#include <BLabel>
#include <BImage>
#include <BIcon>
#include <BVBoxLayout>
#include <BGridLayout>
#include <BHBoxLayout>
#include <BFileDialog>
#include <BColorDialog>
#include <BStyle>

#include "../StringUtils.h"
#include "CameraPanel.h"

CameraPanel::CameraPanel(BWidget* parent) : BasicPanel(parent)
{
	this->setTitle("Camera");

	_camera = 0;

	BLabel* orthoLabel = new BLabel("ortho");
	_orthoCheckBox = new BCheckBox();

	BLabel* widthLabel = new BLabel("width");
	_lensWidthSpinBox = new BRealSpinBox();

	BLabel* heightLabel = new BLabel("height");
	_lensHeightSpinBox = new BRealSpinBox();

	BLabel* nearLabel = new BLabel("near");
	_nearSpinBox = new BRealSpinBox();

	BLabel* farLabel = new BLabel("far");
	_farSpinBox = new BRealSpinBox();

	BLabel* fovyLabel = new BLabel("fovy");
	_fovySpinBox = new BRealSpinBox(0.0, 160);

	BGridLayout* gridLayout = new BGridLayout(this);
	gridLayout->addWidget(0, 0, orthoLabel);
	gridLayout->addWidget(0, 1, _orthoCheckBox);
	gridLayout->addWidget(1, 0, widthLabel);
	gridLayout->addWidget(1, 1, _lensWidthSpinBox);
	gridLayout->addWidget(2, 0, heightLabel);
	gridLayout->addWidget(2, 1, _lensHeightSpinBox);
	gridLayout->addWidget(3, 0, nearLabel);
	gridLayout->addWidget(3, 1, _nearSpinBox);
	gridLayout->addWidget(4, 0, farLabel);
	gridLayout->addWidget(4, 1, _farSpinBox);
	gridLayout->addWidget(5, 0, fovyLabel);
	gridLayout->addWidget(5, 1, _fovySpinBox);

	connect(this, Signal_AssetChanged, &CameraPanel::slotAssetChanged);

	connect(_orthoCheckBox, Signal_Toggled, &CameraPanel::slotOrthoCheckBoxToggled);
	connect(_lensWidthSpinBox, Signal_EditFinished, &CameraPanel::slotLensWidthEditFinished);
	connect(_lensHeightSpinBox, Signal_EditFinished, &CameraPanel::slotLensHeightEditFinished);
	connect(_nearSpinBox, Signal_EditFinished, &CameraPanel::slotNearEditFinished);
	connect(_farSpinBox, Signal_EditFinished, &CameraPanel::slotFarEditFinished);
	connect(_fovySpinBox, Signal_EditFinished, &CameraPanel::slotFovyEditFinished);

}
CameraPanel::~CameraPanel()
{

}

void CameraPanel::slotAssetChanged()
{
	_camera = this->asset();
	if (_camera)
	{
		_orthoCheckBox->setChecked(_camera->ortho());
		_lensWidthSpinBox->setValue(_camera->lensWidth());
		_lensHeightSpinBox->setValue(_camera->lensHeight());
		_nearSpinBox->setValue(_camera->near());
		_farSpinBox->setValue(_camera->far());
		_fovySpinBox->setValue(_camera->fovy());
	}
}
void CameraPanel::slotOrthoCheckBoxToggled(BObject* object, const BValue& value)
{
	bool ortho = value;
	_camera->setOrtho(ortho);
}
void CameraPanel::slotLensWidthEditFinished(BObject* object, const BValue& value)
{
	BReal lensWidth = value;
	_camera->setLensWidth(lensWidth);
}
void CameraPanel::slotLensHeightEditFinished(BObject* object, const BValue& value)
{
	BReal lensHeight = value;
	_camera->setLensHeight(lensHeight);
}
void CameraPanel::slotNearEditFinished(BObject* object, const BValue& value)
{
	BReal near = value;
	_camera->setNear(near);
}
void CameraPanel::slotFarEditFinished(BObject* object, const BValue& value)
{
	BReal far = value;
	_camera->setFar(far);
}
void CameraPanel::slotFovyEditFinished(BObject* object, const BValue& value)
{
	BReal fovy = value;
	_camera->setFovy(fovy);
}

void CameraPanel::styleEvent(const BEvent& event)
{
	BGroupBox::styleEvent(event);
	if (const BStyle* style = this->realStyle())
	{

	}
}
